﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Web;
    using WMS6.Web.OrderDetailMgtServiceRef;

    public class OrderDetailMgtServiceClientProxy : BasePage
    {
        public string DeletePurchaseOrderDetailInfo(List<string> poIDs, List<string> lineIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.DeletePurchaseOrderDetail(poIDs, lineIDs, pubParasInfo);
            }
        }

        public string DeleteSalesOrderDetail(string salesOrderID, List<string> lineIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.DeleteSalesOrderDetail(salesOrderID, lineIDs, pubParasInfo);
            }
        }

        public static OrderDetailMgtServiceClientProxy GetInstance()
        {
            return new OrderDetailMgtServiceClientProxy();
        }

        public PurchaseOrderDetailInfo GetPurchaseOrderDetailInfoBypoIDAndLineID(string poID, string lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.GetPurchaseOrderDetailInfoByID(poID, lineID, pubParasInfo);
            }
        }

        public List<PurchaseOrderDetailInfo> GetPurchaseOrderDetailInfoListBypoID(string poID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.GetPurchaseOrderDetailInfoListByID(poID, pubParasInfo);
            }
        }

        public SalesOrderDetailInfo GetSalesOrderDetailInfoByID(string salesOrderID, string lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.GetSalesOrderDetailInfoByID(salesOrderID, lineID, pubParasInfo);
            }
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertPurchaseOrderDetailInfo(PurchaseOrderDetailInfo purchaseOrderDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.InsertPurchaseOrderDetail(purchaseOrderDetailInfo, pubParasInfo);
            }
        }

        public string InsertSalesOrderDetail(SalesOrderDetailInfo salesOrderDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.InsertSalesOrderDetail(salesOrderDetailInfo, pubParasInfo);
            }
        }

        public string PurchaseOrderDetailPriceChanges(string poID, string lineID, float price)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.PurchaseOrderDetailPriceChanges(poID, lineID, price, pubParasInfo);
            }
        }

        public string UpdatePurchaseOrderDetailInfo(PurchaseOrderDetailInfo purchaseOrderDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.UpdatePurchaseOrderDetail(purchaseOrderDetailInfo, pubParasInfo);
            }
        }

        public string UpdateSalesOrderDetail(SalesOrderDetailInfo salesOrderDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (OrderDetailMgtServiceClient client = new OrderDetailMgtServiceClient("WSHttpBinding_IOrderDetailMgtService"))
            {
                return client.UpdateSalesOrderDetail(salesOrderDetailInfo, pubParasInfo);
            }
        }
    }
}

